import { approvalType, booleanType, conditionType, flowType, operationType } from "../types";
import DividerService from "./divider/service";
import InputControlService from "./input/service";
import ModelIdService from "./modelId/service";
import SelectorService from "./selector/service";
import ApprovalUserSelectorService from "./userSelector/approval/service";
import CCUserSelectorService from "./userSelector/cc/service";

import { selectors as approvalSelectors } from "./userSelector/approval/selectors";
import { selectors as ccSelectors } from "./userSelector/cc/selectors";
import ApprovalTypeService from "./approvalType/service";
import ModelNameService from "./modelName/service";
import CheckboxElementService from "./extensionElement/checkbox";
import RadioElementService from "./extensionElement/radio";
import { Space } from "szcd";
import ExpressionDrawer from "../components/ExpressionDrawer";
import { QuestionCircleOutlined } from "@ant-design/icons";

/** 基础配置 */
const general = {
  id: new InputControlService({ label: 'ID', field: 'id' }),
  name: new InputControlService({ label: '名称', field: 'name' }),
};
/** 流程配置 */
const model = {
  id: new ModelIdService(),
  name: new ModelNameService(),
};
/** 表单配置 */
const form = {
  createPath: new InputControlService({ label: '表单提交路由', field: 'flowable:formCreatePath', type: 'attr' }),
  viewPath: new InputControlService({ label: '表单查询路由', field: 'flowable:formViewPath', type: 'attr' }),
};
/** 流配置 */
const flow = {
  flowType: new SelectorService({
    label: '流转类型',
    options: [
      {
        label: '普通流转路径',
        value: flowType.normalFlow,
      },
      {
        label: '默认流转路径',
        value: flowType.defaultFlow,
      },
      {
        label: '条件流转路径',
        value: flowType.conditionalFlow,
      }
    ]
  }),
  conditionType: new SelectorService({
    label: '条件格式',
    options: [
      {
        label: '表达式',
        value: conditionType.expression,
      }
    ]
  }),
  expression: new InputControlService({
    label: <Space size={[8, 0]}>
      表达式
      <ExpressionDrawer>
        <QuestionCircleOutlined />
      </ExpressionDrawer>
    </Space>
  }),
};

/** 审批 */
const approval = {
  user: new ApprovalUserSelectorService({
    label: '参与人设置',
    selectors: [
      approvalSelectors.user,
      approvalSelectors.initiator,
      approvalSelectors.role,
      approvalSelectors.department
    ]
  }),
  approvalType: new ApprovalTypeService({
    label: '审批类型',
    // field: 'flowable:approvalRemarkIsRequired'
    options: [
      {
        label: '无',
        value: approvalType.none
      },
      {
        label: '或签',
        value: approvalType.or
      },
      {
        label: '会签',
        value: approvalType.and
      }
    ]
  }),
  remarkIsRequired: new CheckboxElementService({
    label: '审批意见',
    element: 'flowable:ApprovalCommentsOption',
    field: 'value',
    types: ['bpmn:UserTask'],
    defaultValue: [booleanType.true],
    options: [
      {
        label: '必填',
        value: booleanType.true
      }
    ]
  })
};

// 抄送
const cc = {
  user: new CCUserSelectorService({
    label: '默认抄送给',
    selectors: [
      ccSelectors.user,
      ccSelectors.role,
      ccSelectors.department
    ]
  }),
  customCc: new RadioElementService({
    label: '自选抄送人',
    element: 'flowable:DefaultCcOption',
    field: 'value',
    defaultValue: booleanType.true,
    types: ['bpmn:UserTask'],
    options: [
      {
        label: '允许',
        value: booleanType.true
      },
      {
        label: '不允许',
        value: booleanType.false
      }
    ]
  })
};

// 操作设置
const setting = {
  operation: new CheckboxElementService({
    label: '操作',
    field: 'value',
    element: 'flowable:Buttons',
    defaultValue: [
      operationType.agree,
      operationType.turnInto,
      operationType.reject,
    ],
    types: ['bpmn:UserTask'],
    options: [
      {
        label: '同意',
        value: operationType.agree
      },
      {
        label: '转办',
        value: operationType.turnInto
      },
      {
        label: '驳回',
        value: operationType.reject
      }
    ]
  }),
};

export const controls = {
  general,
  model,
  form,
  flow,
  approval,
  cc,
  setting,
  divider: new DividerService()
};